package top.xia17.plugins.fast.quartz.initializtion;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import top.xia17.plugins.fast.quartz.core.QuartzJobInfo;
import top.xia17.plugins.fast.quartz.core.QuartzManage;

import java.util.ArrayList;
import java.util.List;

/**
 * spring定时任务注册
 *
 * @author xia17
 * @date 2022/6/13
 */
@RequiredArgsConstructor
public class SpringQuartzJobInfoRegister implements InitializingBean {

    private final List<QuartzJonInitialization> quartzJonInitializationList;
    private final QuartzManage quartzManage;


    @Override
    public void afterPropertiesSet() {
        List<QuartzJobInfo> list = new ArrayList<>();
        for (QuartzJonInitialization quartzJonInitialization : quartzJonInitializationList) {
            List<QuartzJobInfo> quartzJobInfos = quartzJonInitialization.getQuartzJobInfos();
            if (quartzJobInfos != null) {
                list.addAll(quartzJobInfos);
            }
        }
        list.forEach(quartzManage::addJob);
    }
}
